package com.example.security_demo.service;

import com.example.security_demo.dao.UserDao;
import com.example.security_demo.pojo.User;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class UserService {
    @Resource
    private MongoTemplate mongoTemplate;

    public User findByUsername(User user) {
        Query query = new Query();
        query.addCriteria(Criteria.where("username").is(user.getUsername()));
        query.addCriteria(Criteria.where("password").is(user.getPassword()));
        return mongoTemplate.findOne(query, User.class);
    }
}
